home *** CD-ROM | disk | FTP | other *** search
- /* slave.c - This module contains the code to handle processing the slave
- process.
-
- Copyright 1989 by Jeffrey F. Lawhorn (jeffl@berick.uucp)
-
- This file is part of vuser.
-
- vuser is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your
- option) any later version.
-
- vuser is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNU CC; see the file COPYING. If not, write to the
- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #if !defined(lint)
- static char SCCSid[] = "$Id: slave.c,v 1.1 89/12/15 21:31:13 jeffl Exp $";
- #endif
-
- #include <stdio.h>
- #include <signal.h>
- /* #include <sys/wait.h> */
-
- #if defined(__STDC__)
- extern void Tty2ShellMode();
- extern void SlavePty2Stdio();
- extern char *getenv(char *);
- #else
- extern void Tty2ShellMode();
- extern void SlavePty2Stdio();
- extern char *getenv();
- #endif
-
- int SlavePid = 0;
- char **Program2Run = (char **)NULL;
- char *RloginProgram[] = {
- "rlogin",
- "rlogin",
- NULL,
- "-l",
- NULL,
- NULL,
- };
-
- void RunSlaveProgram()
- {
- char *ptr = (char *)NULL;
- char tmp[1024];
-
- if(RloginProgram[2]) {
- execlp(RloginProgram[0], RloginProgram[1], RloginProgram[2],
- RloginProgram[3], RloginProgram[4], RloginProgram[5]);
- perror("rlogin: ");
- Tty2ShellMode();
- exit(1);
- }
- if(Program2Run) {
- execvp(Program2Run[0], Program2Run);
- perror(Program2Run[0]);
- Tty2ShellMode();
- exit(1);
- }
- if(!(ptr = getenv("SHELL")))
- strcpy(tmp, "/bin/sh");
- else
- strcpy(tmp, ptr);
- execlp(tmp, tmp, (char *)0);
- perror("starting slave: ");
- Tty2ShellMode();
- exit(1);
- }
-
- void KillSlave()
- {
- kill(SlavePid, SIGTERM);
- sleep(15);
- kill(SlavePid, SIGKILL);
- sleep(2);
- Tty2ShellMode();
- exit(1);
- }
-
- DeadSlave()
- {
- /* union wait status; */
- unsigned int status;
-
- if(wait(&status) != SlavePid) {
- signal(SIGCLD, DeadSlave);
- fprintf(stderr, "Someone else's child just killed me!!!\n");
- fprintf(stderr, "Shutting down.\n");
- KillSlave();
- }
- Tty2ShellMode();
- exit(0);
- }
-
- void StartSlave()
- {
- signal(SIGCLD, DeadSlave);
- if((SlavePid = fork()) < 0) {
- perror("on fork: ");
- Tty2ShellMode();
- exit(1);
- }
- if(!SlavePid) {
- SlavePty2Stdio();
- RunSlaveProgram();
- }
- return;
- }
-